/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package bpmn.impl;

import bpmn.BpmnPackage;
import bpmn.Category;
import bpmn.GraphicalElement;
import bpmn.Group;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;

import org.eclipse.emf.ecore.util.EObjectResolvingEList;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Group</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link bpmn.impl.GroupImpl#getCategoryRef <em>Category Ref</em>}</li>
 *   <li>{@link bpmn.impl.GroupImpl#getGraphicalElements <em>Graphical Elements</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class GroupImpl extends ArtifactImpl implements Group {
	/**
	 * The cached value of the '{@link #getCategoryRef() <em>Category Ref</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getCategoryRef()
	 * @generated
	 * @ordered
	 */
	protected Category categoryRef;

	/**
	 * The cached value of the '{@link #getGraphicalElements() <em>Graphical Elements</em>}' reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getGraphicalElements()
	 * @generated
	 * @ordered
	 */
	protected EList<GraphicalElement> graphicalElements;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected GroupImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return BpmnPackage.Literals.GROUP;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Category getCategoryRef() {
		if (categoryRef != null && categoryRef.eIsProxy()) {
			InternalEObject oldCategoryRef = (InternalEObject)categoryRef;
			categoryRef = (Category)eResolveProxy(oldCategoryRef);
			if (categoryRef != oldCategoryRef) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, BpmnPackage.GROUP__CATEGORY_REF, oldCategoryRef, categoryRef));
			}
		}
		return categoryRef;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Category basicGetCategoryRef() {
		return categoryRef;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setCategoryRef(Category newCategoryRef) {
		Category oldCategoryRef = categoryRef;
		categoryRef = newCategoryRef;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, BpmnPackage.GROUP__CATEGORY_REF, oldCategoryRef, categoryRef));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<GraphicalElement> getGraphicalElements() {
		if (graphicalElements == null) {
			graphicalElements = new EObjectResolvingEList<GraphicalElement>(GraphicalElement.class, this, BpmnPackage.GROUP__GRAPHICAL_ELEMENTS);
		}
		return graphicalElements;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case BpmnPackage.GROUP__CATEGORY_REF:
				if (resolve) return getCategoryRef();
				return basicGetCategoryRef();
			case BpmnPackage.GROUP__GRAPHICAL_ELEMENTS:
				return getGraphicalElements();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case BpmnPackage.GROUP__CATEGORY_REF:
				setCategoryRef((Category)newValue);
				return;
			case BpmnPackage.GROUP__GRAPHICAL_ELEMENTS:
				getGraphicalElements().clear();
				getGraphicalElements().addAll((Collection<? extends GraphicalElement>)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case BpmnPackage.GROUP__CATEGORY_REF:
				setCategoryRef((Category)null);
				return;
			case BpmnPackage.GROUP__GRAPHICAL_ELEMENTS:
				getGraphicalElements().clear();
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case BpmnPackage.GROUP__CATEGORY_REF:
				return categoryRef != null;
			case BpmnPackage.GROUP__GRAPHICAL_ELEMENTS:
				return graphicalElements != null && !graphicalElements.isEmpty();
		}
		return super.eIsSet(featureID);
	}

} //GroupImpl
